package com.hzdesk.media.koreabatchmatvector.fragment.fragment_view;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.InputDevice;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.base.MyClientApplication;
import com.hzdesk.media.koreabatchmatvector.bean.MouseUserDevicesinfoBean;
import com.hzdesk.media.koreabatchmatvector.bean.MousetBean;
import com.hzdesk.media.koreabatchmatvector.bean.UserBean;
import com.hzdesk.media.koreabatchmatvector.config.RxBusUtil;
import com.hzdesk.media.koreabatchmatvector.fragment.fragment_contract.MouseSetContract;
import com.hzdesk.media.koreabatchmatvector.fragment.fragment_persenter.MouseSetPersenter;
import com.hzdesk.media.koreabatchmatvector.logic.view.BaseActivity;
import com.hzdesk.media.koreabatchmatvector.matvector.NiceSpinner;
import com.hzdesk.media.koreabatchmatvector.utils.RxBus;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/22.
 * 杭州席媒科技有限公司  Developers  刘传华  15
 * 佛祖镇楼 bug辟易
 */

public class MouseSetFragment extends BaseFragment  implements MouseSetContract.IMouseSetView{

    @BindView(R.id.fragment_my_mouse_set_tv_number)
    TextView fragmentMyMouseSetTvNumber;
    @BindView(R.id.fragment_my_mouse_set_checkbox)
    CheckBox fragmentMyMouseSetCheckbox;
    @BindView(R.id.fragment_my_mouse_set_et_name)
    EditText fragmentMyMouseSetEtName;
    @BindView(R.id.fragment_my_mouse_set_nice_spinner_one)
    NiceSpinner fragmentMyMouseSetNiceSpinnerOne;
    @BindView(R.id.fragment_my_mouse_set_nice_spinner_two)
    NiceSpinner fragmentMyMouseSetNiceSpinnerTwo;
    @BindView(R.id.fragment_my_mouse_set_tv_cancle)
    TextView fragmentMyMouseSetTvCancle;
    @BindView(R.id.fragment_my_mouse_set_tv_confirm)
    TextView fragmentMyMouseSetTvConfirm;
    Unbinder unbinder;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    private MouseSetPersenter mMouseSetPersenter = new MouseSetPersenter(this);
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_mouse_set, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initDate();
    }

    private void initDate() {
        fragmentMyMouseSetNiceSpinnerOne.setTextColor(getContext().getResources().getColor(R.color.dialogtextcolor));
        fragmentMyMouseSetNiceSpinnerTwo.setTextColor(getContext().getResources().getColor(R.color.dialogtextcolor));
        mMouseSetPersenter.initDate(fragmentMyMouseSetNiceSpinnerOne,fragmentMyMouseSetNiceSpinnerTwo,mcontext);
        mMouseSetPersenter.setinitListener(fragmentMyMouseSetCheckbox,mcontext);
    }


    @OnClick({R.id.fragment_my_mouse_set_tv_cancle, R.id.fragment_my_mouse_set_tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fragment_my_mouse_set_tv_cancle:
                mMouseSetPersenter.onClickCancle(RxBusUtil.CHANGE_MOUSE_LIST_FRAGMENR);
                break;
            case R.id.fragment_my_mouse_set_tv_confirm:
                mMouseSetPersenter.onClickConfirm(mcontext);
                break;
        }
    }
    @Override
    public void setupdateView(MouseUserDevicesinfoBean userBean) {
        fragmentMyMouseSetEtName.setText(userBean.getName());
    }

    @Override
    public void setOneSelectedIndex(int index) {
        fragmentMyMouseSetNiceSpinnerOne.setSelectedIndex(index);
    }

    @Override
    public void setTwoSelectedIndex(int index) {
        fragmentMyMouseSetNiceSpinnerTwo.setSelectedIndex(index);
    }

    @Override
    public String getEtName() {
        return fragmentMyMouseSetEtName.getText().toString().trim();
    }

    @Override
    public void sendMessage(int pager) {
        RxBus.getInstance().send(pager);
    }

    @Override
    public void setTvNumber(String msg) {
        fragmentMyMouseSetTvNumber.setText(msg);
    }

    @Override
    public String getMouseSetName() {
        return fragmentMyMouseSetEtName.getText().toString().trim();
    }

    @Override
    public void setMouseSetName(String name) {
        fragmentMyMouseSetEtName.setText(name);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        RxBus.getInstance().unSubcribe();
    }

}
